package com.hitqz.robot.biz.flow.component.common;

import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.json.JSONObject;
import com.google.common.cache.Cache;
import com.hitqz.robot.biz.flow.domain.constant.FlowConstant;
import com.hitqz.robot.biz.flow.util.LiteFlowUtil;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j;

import java.util.Optional;

/**
 * 步骤组件 清除偏移距离
 *
 * @author wengyx
 * @date 2023/11/19
 */
@LiteflowComponent(value = "sleep",name = "[通用组件]延时")
@Slf4j
public class sleep extends NodeComponent {
    @Override
    public void process() throws Exception {
        //通过规则中的.data()获取参数
        String key = FlowConstant.NODE_CUSTOM_INFO_MAP.get(this.getNodeId()).getParamNames().get(0);
        Integer cmd = this.getCmpData(JSONObject.class).get(key, Integer.class);
        cmd = Math.max(0,cmd);
        log.info("[liteFlow]延时:{}",cmd);
        for (int i = 0; i < cmd; i++) {
            LiteFlowUtil.checkInterruptFlag();
            Thread.sleep(1000);
        }
    }
}
